<template>
	<view class="mian11">
		<view class="tab-bar">
			<view  v-for="(item,index) in tabbarList" :key="index" @click="tabbarClick(item)">
				<view :class="item.name == '发布' ? 'dierge' : 'tab-item'">
					<image :src="currPagePath.includes(item.path) ? item.image : item.img" class="image"></image>
					<text :class="currPagePath.includes(item.path) ? 'textt' : 'txt'">{{item.name}}</text>
				</view>
			</view>
			
			<view>
				<!-- 普通弹窗 -->
				<uni-popup ref="popup" :is-mask-click="false">
					<view class="popup-content">
						<view class="popup_item" @tap="torelease_transfer()">
							<image class="item_image" src="../../static/images/发布转租.png"></image>
							<view class="textone">
								<p class="pone">店铺转让</p>
								<p class="ptwo">让更多人找店的人看到</p>
							</view>
						</view>
						<view class="hrone"></view>
						<view class="popup_item" @tap="torelease_hire()">
							<image  class="item_image" src="../../static/images/发布求租.png"></image>
							<view class="textone">
								<p class="pone">我要找店</p>
								<p class="ptwo">快速找店减少时间成本</p>
							</view>
						</view>
						<i class="close" @tap.stop="colse_popup()"></i>
					</view>
				</uni-popup>
			</view>
		</view>
	</view>
</template>

<script setup>
	import {ref,reactive,onMounted,onBeforeMount} from 'vue';
	import {addClick} from '../../util/api.js'
	// import tabbervalue from '../../util/common/tabbarvalue.js'
	// import { inject } from 'vue';

	// 在组件渲染之前执行
	onBeforeMount(() => {
		console.log('组件准备渲染',);
	})
	// 当前页面path
	const currPagePath = ref('');
	// let tabbervalue = reactive({
	// 	oldrouter:'',
	// 	already:0,
	// })
	// 表单
	const tabbarList = reactive([{
			name: '首页',
			path: 'pages/index/index',
			img:'../../static/images/首.png',
			image:'../../static/images/首页-选中.png'
		},
		{
			name: '发布',
			// path: "/release_transfer/release_transfer",
			img:'../../static/images/发布.png',
			image:'../../static/images/发布.png',
			// icon: 'plus-filled',
			// 是否为弹窗
			isPopup: true,
		},
		{
			name: '我的',
			path: 'pages/my/my',
			img:'../../static/images/我的-2.png',
			image:'../../static/images/我的-2(1).png'
		}
	])

	// 跳转函数
	const torelease_transfer = () =>{
		addClick('小程序_弹窗店铺转让')
				// 先关闭遮罩层
		popup.value.close()
		const openid = uni.getStorageSync('open_id') || '';
		if(openid == ''){
			uni.switchTab({
				url: '/pages/my/my'
			});

		}else{
			uni.navigateTo({
				url: '/pages/release_transfer/release_transfer'
			});
		}
	}
	const torelease_hire = () =>{
		addClick('小程序_弹窗我要找店')
		// 先关闭遮罩层
		popup.value.close()
		const openid = uni.getStorageSync('open_id') || '';
		if(openid == ''){
			uni.redirectTo({
				url: '/pages/login/login'
			});
		}else{
			uni.navigateTo({
				url: '/pages/release_hire/release_hire'
			});
		}

	}

	// 关闭遮罩层
	const colse_popup = () =>{
		popup.value.close()
	}

	// 定义ref的初始值
	const popup = ref(null)
	// 点击事件
	const tabbarClick = (item) => {
		// console.log("item",item)
		if(item.name == '发布'){
			addClick('小程序_发布按钮')
		}
		//解构赋值, 重置弹窗隐藏
		const {
			name,
			path,
			isPopup
		} = item;
		// 是否为弹窗，否则不跳转路由
		if (isPopup) {
		// open 方法传入参数 等同在 uni-popup 组件上绑定 type属性
			popup.value.open('center')
			return;
		}
		uni.switchTab({
			url: `/${path}`
		});

		// console.log("前一个页面的变量",tabbervalue.oldrouter+ '和现在的'+path)
		// tabbervalue.oldrouter = uni.getStorageSync('oldrouter') || '';
		// tabbervalue.already = uni.getStorageSync('already') || '0';
		// if(tabbervalue.oldrouter != path){
		// 	console.log("1上个页面",tabbervalue.oldrouter)
		// 	tabbervalue.oldrouter = currPagePath.value 
		// 	uni.setStorageSync('oldrouter', tabbervalue.oldrouter);
		// 	console.log("11上个页面",tabbervalue.oldrouter)
		// 	// 跳转路由
		// 	uni.navigateTo({
		// 		url: `/${path}`
		// 	});
		// }else if(tabbervalue.already == '0'){
		// 	console.log("2上个页面",tabbervalue.oldrouter)
		// 	// 吧当前页面的地址变成上个页面的地址进行跳转
		// 	tabbervalue.oldrouter = currPagePath.value 
		// 	// 申明一个值代表已经跳转过来了
		// 	console.log("1111tabbervalue.oldrouter",tabbervalue.already)
		// 	// tabbervalue.already == '1'		
		// 	uni.setStorageSync('oldrouter', tabbervalue.oldrouter);
		// 	uni.setStorageSync('already', '1');
		// 	console.log("22上个页面",tabbervalue.oldrouter)
		// 	uni.navigateBack({
		// 		delta: 1
		// 	});
		// }else if(tabbervalue.already == '1'){
		// 	console.log("3上个页面",tabbervalue.oldrouter)
		// 	// 吧当前页面的地址变成上个页面的地址进行跳转
		// 	tabbervalue.oldrouter = currPagePath.value 
		// 	// 申明一个值代表已经跳转两次之后恢复原样
		// 	console.log("2222tabbervalue.oldrouter",tabbervalue.already)
		// 	// tabbervalue.already == '0'
		// 	uni.setStorageSync('oldrouter', tabbervalue.oldrouter);
		// 	uni.setStorageSync('already','0');
		// 	console.log("33上个页面",tabbervalue.oldrouter)
		// 	uni.navigateBack({
		// 		delta: -1
		// 	});
		// }
	};

	// 挂载完成之后的钩子
	onMounted(() => {
		const pages = getCurrentPages();
		const currentPage = pages[pages.length - 1];
		const pagePath = currentPage.route;
		currPagePath.value = pagePath;
		console.log('当前页面地址:', currPagePath.value);
	});
</script>

<style lang="scss">
	.mian11{
		font-family: '思源黑体';
		width:  100%;
		height: 120rpx;
		background-color: #fff;
		border-radius: 20rpx;
	}
	.tab-bar {
		width: 750rpx;
		margin: 0 auto;
		display: flex;
		justify-content: space-around;
		align-items: center;
		background-color: #fff;
		border-radius: 20rpx;
		// 去掉微信点击之后的蓝色背景
		-webkit-tap-highlight-color: transparent;
	}

	.tab-item {
		// flex: 1;
		width: 220rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		cursor: pointer;
		// border: 1px solid black;
		.image{
			width: 48rpx;
			height: 48rpx;
			margin-top: 10rpx;
		}
		.txt{
			margin-top: -4rpx;
			font-size: 26rpx;
		}
	}
	.textt{
		color: #f20;
		margin-top: -4rpx;
		font-size: 26rpx;
	}
	.dierge{
		// flex: 1;
		width: 220rpx;
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
		cursor: pointer;
		// border: 1px solid black;
		.image{
			width: 100rpx;
			height: 100rpx;
			margin-top: -44rpx;
		}
		.txt{
			margin-top: 2rpx;
			font-size: 26rpx;
		}
	}

	.popup-content{
		width: 660rpx;
		height: 410rpx;
		font-family: '思源黑体';
		color: rgba(46, 46, 46, 1);
		border-radius: 20rpx;
		// border-radius: 20rpx;
		.popup_item{
			width: 660rpx;
			height: 200rpx;
					// border: 1px solid black;
			// background-color: pink;
			display: flex;
			.item_image{
				width: 130rpx;
				height: 130rpx;
				margin: 30rpx 0 0 40rpx;
			}
			.textone{
				widows: 300rpx;
				height: 120rpx;
				margin: 30rpx 0 0 40rpx;
				.pone{
					margin-top: 10rpx;
					font-size: 36rpx;
					font-weight: 700;
				}
				.ptwo{
					margin-top: 10rpx;
					font-size: 28rpx;
					font-weight: 400;	
				}
			}
		}
		.hrone{
			width: 600rpx;
			height: 2rpx;
			margin: 0 auto;
			border-top: 1px dashed rgba(207, 204, 204, 1);

		}
		.close{
			display: inline-block;
			width: 80rpx;
			height: 80rpx;
			margin: 40rpx 0 0 280rpx; 
			background: url(../../static/images/7.png);
			background-size: 100% 100%;
		}
	}
	:deep(.popup-content) {
		// border-radius: 20rpx;
		background-color: #f5f5f5;
	}
</style>